I want to check a string if it has a format like an object number (e.g. 1.12.3) in preparation for a filter. |
Re: Checking string using regexp string strToken = "^[0-9]*(\.[0-9]*)*$" -E- DXL: <Line:11> badly formed token ("[0-9]*(\.[0-9]*)*") |
Re: Checking string using regexp string strToken = "^0-9*(\\.0-9*)*$" print strToken prints this: ^0-9*(\.0-9*)*$
|
Re: Checking string using regexp StefanLieser - Wed May 19 10:20:38 EDT 2010
You need to use double backslashes in a string in DXL, and I would suggest you allow the "-" as a separator and make sure that there is at least one number after a separator and at the start of the line number. So try like this: string strToken = "^[0-9]+([\\.-][0-9]+)*$"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Checking string using regexp
Oh. And don't forget you must be able to handle DOORS formatted paragraph 'Numbers', including "3.2.0-1" and "3.2.0-1.3" and "3.2.0-1.3.0-1".
//************************
bool fIsParaNum(string InWord)
{ // Determine if the input string appears to be a
// valid paragraph number. i.e. all characters are
// digits, periods, or dashes, AND periods and dashes
// are surrounded by digits.
// e.g. 3.12.0-4.3.0-34
int len = length(InWord)
int i
if (len <=0) return(false) // RETURN: empty InWord
for (i=0; i<len; i++)
{
if (InWord[i] != '.' and
InWord[i] != '-' and
!isdigit(InWord[i]))
return(false) // RETURN: illegal character
if (isdigit(InWord[i])) continue // digit OK
// this Char is '.' or '-'
if (i == 0 or i == len-1)
return(false) // RETURN: first and last characters
// must be digits
if (!isdigit(InWord[i-1]) or
!isdigit(InWord[i+1]))
return(false) // RETURN: . and - must be surrounded by digits
// are not digits
} // end for each character in InWord.
return(true) // survived all checks.
} // end fIsParaNum()
|
Re: Checking string using regexp llandale - Wed May 19 12:09:25 EDT 2010
Thank you very much! |